package com.wenlin.userservice.service.impl;

import com.wenlin.userservice.domain.Test;
import com.wenlin.userservice.mapper.TestMapper;
import com.wenlin.userservice.response.Message;
import com.wenlin.userservice.service.TestService;
import com.wenlin.userservice.util.Switch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/***
 *  Created with IntelliJ IDEA.
 *  User:  wenlin
 *  Date:  2017/12/1
 *  Time:  16:30
 *  Description:
 **/
@Service
public class TestServiceImpl implements TestService{

    public static Integer flag = null;

    @Autowired
    private TestMapper testMapper;
    @Override
    public Message<Test> get() {
        Test test = testMapper.select(1);
        return new Message<Test>(test);
    }

    @Override
    @Transactional
    public Message update(Integer flag) {
        Message message = new Message();
        int count = testMapper.updateFlag(flag);
        if(count!=1){
            message.setCode(1);
            message.setMsg("修改失败");
            return message;
        }
        Switch s1 = Switch.getInstance();
        s1.setFlag();
        return message;
    }

    @Override
    public Message getFlag() {
        Switch s1 = Switch.getInstance();
        Integer flag = s1.getFlag();
        Message message = new Message();
        message.setData(flag);
        return message;
    }
}
